package com.mujin.keji.collectionsystem.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;

/**
 * 选择交通工具
 *
 * @author weishixiong
 * @Time 2018-05-10
 */


public class SelectSexPopWindow extends PopupWindow {
    private Activity context;
    private TextView tvBoy;
    private TextView tvGirl;
    private TextView tvCancel;
    private SelectSexLisenter lisenter;

    /**
     * 性别选择
     */
    public interface SelectSexLisenter {

        void onSelect(String sex);
    }

    /**
     * @param context
     */
    public SelectSexPopWindow(final SelectSexLisenter lisenter, final Activity context) {
        this.context = context;
        this.lisenter = lisenter;
        //获得 LayoutInflater 的实例
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView = inflater.inflate(R.layout.pop_select_sex, null);
        this.setContentView(contentView);
        tvBoy = (TextView) contentView.findViewById(R.id.tv_boy);
        tvGirl = (TextView) contentView.findViewById(R.id.tv_girl);
        tvCancel = (TextView) contentView.findViewById(R.id.tv_cancel);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        tvBoy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                lisenter.onSelect(tvBoy.getText().toString());
                dismiss();
            }
        });
        tvGirl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                lisenter.onSelect(tvGirl.getText().toString());
                dismiss();
            }
        });
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        this.setFocusable(true);
        this.setOutsideTouchable(true);
//        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(Color.parseColor("#80000000"));
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        setBackgroundDrawable(dw);
    }

}
